<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/common/common.jsp" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    
    <title>操作管理</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="操作,管理">
	<meta http-equiv="description" content="This is my page">
	
	<link rel="stylesheet" type="text/css" href="${CONTEXT_PATH}/common/tree/treeCss.css">
	<script type="text/javascript" src="${CONTEXT_PATH}/common/tree/jquery.simple.tree.js"></script>
	
	<script type="text/javascript">
	
	var x = '';
	
	var simpleTreeCollection;
	$(document).ready(function(){
		simpleTreeCollection = $('#simpleTree').simpleTree({
			drag:false,
			docToFolderConvert:true,
			afterClick:function(node){
				var id = node.attr('id');
				x = id.substring(2);//模块id
			}
		});
	});
	
	
	function addPrivilege()
	{
		if(!checkInfo())
		{
			return;
		}
		var url = '${CONTEXT_PATH}/inner/privilege/toAddPrivilege.action?parentPrivilege.id=' + x + '&timestamp=' + Date.parse(new Date());
		showMd(url, 550, 350);
	}
	
	
	//判断是否有选中
	function checkInfo()
	{
		var li = $('#li' + x);
		if(li.length < 1)
		{
			showMsg('请先选择节点');
			return false;
		}
		return true;
	}
	
	
	function updatePrivilege()
	{
		if(!checkInfo())
		{
			return;
		}
		$.ajax({
    		url:'${CONTEXT_PATH}/inner/privilege/updateCheck.action?privilege.id=' + x + '&timestamp=' + Date.parse(new Date()),
    		type:'post',
    		dataType:'json',
    		success:
    			function(result){
    				if(result == true)
    				{
    					var url = '${CONTEXT_PATH}/inner/privilege/toUpdatePrivilege.action?privilege.id=' + x;
    					showMd(url, 550, 350);
    				}
    				else
    				{
    					showMsg('只能修改操作。');
    				}
    			}
    	});
	}
	
	function delPrivilege()
	{
		if(!checkInfo())
		{
			return;
		}
		showConfirm('确认删除？', function(v){
    		if(v == true)
    		{
    			$.ajax({
		    		url:'${CONTEXT_PATH}/inner/privilege/delPrivilege.action?privilege.id=' + x,
		    		type:'post',
		    		dataType:'json',
		    		success:
		    			function(result){
		    				if(result == true)
		    				{
			    				showMsg('删除成功。', function(){
			    					simpleTreeCollection.get(0).delNode();
						    	});
					    	}
					    	else
					    	{
					    		showMsg('只能删除操作。');
					    	}
		    			}
		    	});
    		}
    	});
	}
	</script>

  </head>
  
  <body style="margin:-22px -22px 0px -22px">
  	<s:form name="frm" id="frm" method="post">
	  	<jsp:include page="/jsp/outward/business/common/menuLink.jsp">
	 		<jsp:param name="menuLink" value="[{'name':'系统管理'},{'name':'权限管理'},{'name':'操作管理'}]"/>
	 		<jsp:param name="width" value="40%"/>
	 	</jsp:include>
	  	<table width="100%" height="90%" cellspacing="0">
	  		<tr>
	  			<td height="5%" align="left" valign="top">
	  			
	  				<table cellspacing="0">
				    	<tr>
				    		<my:hasPermission privilegeId="updateOperation">
				    		<td width="120px" align="left">
				    			<input type="button" onclick="updatePrivilege()" value="修改操作" class="btn" />
				    		</td>
				    		</my:hasPermission>
				    		<my:hasPermission privilegeId="addOperation">
				    		<td width="120px" align="left">
				    			<input type="button" onclick="addPrivilege()" value="新增操作" class="btn" />
				    		</td>
				    		</my:hasPermission>
				    		<my:hasPermission privilegeId="delOperation">
				    		<td width="120px" align="left">
				    			<input type="button" onclick="delPrivilege()" value="删除操作" class="btn" />
				    		</td>
				    		</my:hasPermission>
				    	</tr>
				    </table>
				    
	  			</td>
	  		</tr>
	  		<tr>
	  			<td align="left" valign="top" height="95%">
	  				<div style="width:100%; height:100%; overflow-y:auto">
	  				
	  					<ul id="simpleTree" class="simpleTree">
							<li class="root" id="li0"><span>主菜单</span>
								<s:property value="tree" escape="false"/>
							</li>
						</ul>
						
	  				</div>
	  			</td>
	  		</tr>
	  	</table>
    </s:form>
  </body>
</html>
